﻿using System;
using System.Collections.Specialized;
using System.Web.UI;

namespace PD.Web.DynamicData.FieldTemplates
{
    /// <summary>
    /// Represents the multiline text field template control.
    /// </summary>
    public partial class MultilineText_EditField : System.Web.DynamicData.FieldTemplateUserControl
    {
        /// <summary>
        /// Gets the data control that handles the data field in a field template.
        /// </summary>
        /// <returns>A data control that handles the data field in a field template.</returns>
        public override Control DataControl
        {
            get
            {
                return this.TextBox1;
            }
        }

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.TextBox1.MaxLength = this.Column.MaxLength;
            this.TextBox1.ToolTip = this.Column.Description;

            this.SetUpValidator(this.RequiredFieldValidator1);
            this.SetUpValidator(this.RegularExpressionValidator1);
            this.SetUpValidator(this.DynamicValidator1);
        }

        /// <summary>
        /// Provides dictionary access to all data in the current row.
        /// </summary>
        /// <param name="dictionary">The dictionary that contains all the new values.</param>
        protected override void ExtractValues(IOrderedDictionary dictionary)
        {
            dictionary[this.Column.Name] = this.ConvertEditedValue(this.TextBox1.Text);
        }
    }
}
